Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TS definitions #43

Closed
wants to merge 1 commit into from
Closed

Fix TS definitions #43

wants to merge 1 commit into from

Conversation

iamakulov
Copy link

The source code uses module.exports = ..., not exports.default = ...:

clean-deep/src/index.js

Lines 14 to 22 in 9d8313d

module.exports = function cleanDeep(object, {
cleanKeys = [],
cleanValues = [],
emptyArrays = true,
emptyObjects = true,
emptyStrings = true,
nullValues = true,
undefinedValues = true
} = {}) {

Given this, TS definitions should use export =, not export default. See microsoft/TypeScript#7185 (comment).

This matters when the project is compiled without the "esModuleInterop": true flag. In that case, doing

import cleanDeep from 'clean-deep'

cleanDeep(...)

would throw an error like TypeError: clean_deep_1.default is not a function.

The source code uses `module.exports = ...`, not `exports.default = ...`:

https://github.com/nunofgs/clean-deep/blob/9d8313db868b239b990f9db352215844ad7ae65a/src/index.js#L14-L22

Given this, TS definitions should use `export =`, not `export default`. See microsoft/TypeScript#7185 (comment).

This matters when the project is compiled _without_ the `"esModuleInterop": true` flag. In that case, doing

```ts
import cleanDeep from 'clean-deep'

cleanDeep(...)
```

would throw an error like `TypeError: clean_deep_1.default is not a function`.
@FFKL
Copy link
Contributor

FFKL commented Jun 25, 2020

@iamakulov cool! What about CleanOptions? Should be moved intonamespace?

@iamakulov
Copy link
Author

What about CleanOptions? Should be moved intonamespace?

Dunno. Why?

@FFKL
Copy link
Contributor

FFKL commented Jun 26, 2020

Because you overwright exports object by the cleanDeep function and can't use export = with other exports. example

@nunofgs
Copy link
Owner

nunofgs commented Aug 19, 2020

Good point @FFKL . Not sure this can be achieved with the = syntax since you can't really export two things as the "default"
(ultimately they need to be attached somewhere).

Closing for now but please do reopen if you have other suggestions. Thanks!

@nunofgs nunofgs closed this Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants